import threading


class MusicPlayer:
    #1.记录实例对象
    instance = None
    #2,记录是否初始化
    flag = False
    #3.__new__方法为对象分配空间
    def __new__(cls, *args, **kwargs):
        if cls.instance is None:
            #调用父类分配空间
            cls.instance = super().__new__(cls)
            #返回实例对象
            return cls.instance

    #4.init初始化函数

    def __init__(self):
        if MusicPlayer.flag==False:

            MusicPlayer.flag =True

def baidu():
    print('第一种方式')


class MyThread(threading.Thread):
    def run(self):
        print('第二种方式',self.name)

if __name__ == '__main__':
    #第一种通过threading.thread()
    th = threading.Thread(target=baidu)
    th.start()

    #第二种通过创建线程类
    m1 = MyThread()
    m1.start()

    m2 = MyThread(name= 'baidu')
    m2.start()